const { upload } = require("../utils/upload");

module.exports = {
  // 上传图片
  upload: async (ctx, next) => {

    let err = await upload.single('file')(ctx, next)
      .then(res => res)
      .catch(err => err)
    if (err) {
      ctx.body = {
        code: 0,
        msg: err.message
      }
    } else {
      ctx.req.file.filename = "http://127.0.0.1:3000/uploads/" + ctx.req.file.filename
      ctx.body = {
        code: 200,
        msg: "上传成功",
        data: ctx.req.file
      }
    }
  }
}